package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.MessageContent;
import cn.wolfcode.trip.base.domain.PrivateMessage;
import cn.wolfcode.trip.base.domain.Tag;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.mapper.MessageContentMapper;
import cn.wolfcode.trip.base.mapper.PrivateMessageMapper;
import cn.wolfcode.trip.base.mapper.UserMapper;
import cn.wolfcode.trip.base.query.PrivateMessageQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IPrivateMessageService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PrivateMessageServiceImpl implements IPrivateMessageService {
    @Autowired
    private PrivateMessageMapper privateMessageMapper;
    @Autowired
    private MessageContentMapper messageContentMapper;

    @Override
    public void updateBySenderId(Long senderId) {
        privateMessageMapper.updateBySenderId(senderId);
    }

    @Override
    public void updateBrower(Long id) {
        privateMessageMapper.updateBrower(id);
    }

    @Override
    public List<User> getReceiver(QueryObject qo) {
        return privateMessageMapper.selectReceiverReBysenderId(qo);
    }

    Tag t = new Tag();
    @Override
    public void save(PrivateMessage privateMessage) {
        t.setName("a");
        //获取信息内容对象
        MessageContent content = privateMessage.getMessageContent();
        //先保存聊天内容
        messageContentMapper.insert(content);
        //设置信息表中内容id
        privateMessage.setMessageContent(content);
        privateMessageMapper.insert(privateMessage);



    }

    @Override
    public PageInfo query(PrivateMessageQueryObject qo) {
        if (t.getName().equals("a")) {
            PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
            List<PrivateMessage> list = privateMessageMapper.selectForList(qo);
            t.setName("b");
        return new PageInfo(list);
        }
        return null;
    }
}
